]> dgit.raspbian.org Git - opendht.git/commitdiff
http: fix service name resolution failure
authorFrançois-Simon Fauteux-Chapleau <francois-simon.fauteux-chapleau@savoirfairelinux.com>
Mon, 14 Apr 2025 17:25:02 +0000 (13:25 -0400)
committerAdrian Bunk <bunk@debian.org>
Sat, 17 Oct 2026 19:47:08 +0000 (22:47 +0300)
Gbp-Pq: Name 0001-http-fix-service-name-resolution-failure.patch

src/http.cpp

index 6b7d4aadb408f4d1b618bd1bf3e6c3a902d6c5ee..8290268bf2728973d84f31ef2280dbdba2f7e1d1 100644 (file)
@@ -831,10 +831,21 @@ Resolver::add_callback(ResolverCb cb, sa_family_t family)
 }
 
 void
-Resolver::resolve(const std::string& host, const std::string& service)
+Resolver::resolve(const std::string& host, const std::string& serviceName)
 {
-    asio::ip::tcp::resolver::query query_(host, service);
-    resolver_.async_resolve(query_, [this, host, service, destroyed = destroyed_]
+    auto service = serviceName;
+    // The async_resolve function used below typically relies on the contents of the
+    // /etc/services (Linux/POSIX) or c:\windows\system32\drivers\etc\services (Windows)
+    // file in order to resolve a descriptive service name into a port number. A
+    // resolution attempt that would otherwise succeed can therefore fail if the file
+    // is inaccessible or corrupted (which is rare but can happen in practice). We
+    // hardcode the port numbers for http and https to prevent this failure mode.
+    if (service == "http") {
+        service = "80";
+    } else if (service == "https") {
+        service = "443";
+    }
+    resolver_.async_resolve(host, service, [this, host, service, destroyed = destroyed_]
         (const asio::error_code& ec, asio::ip::tcp::resolver::results_type endpoints)
     {
         if (ec == asio::error::operation_aborted or *destroyed)